<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class bgViewbg extends JView
{
    protected $result;
    protected $pagination;
    protected $details;
    protected $update_group;
    protected $total_group;
	// Overwriting JView display method
	function display($tpl = null) 
	{
	   JHTML::_('behavior.formvalidation');
	   $task = JRequest::getVar('task');
       $model = $this->getModel();
       $aut = new bgAuthorize();
       
       switch($task){
            case 'error':
                $code = JRequest::getVar('old_code');
                $this->update_group = $model->getGroupByCode($code);   
                if($this->update_group->MAGR_USERTYPE != 2)
                    $this->total_group = $model->searchUser(array('type' => $this->update_group->MAGR_USERTYPE));    
                $this->details = $model->getDetails($this->update_group->MAGR_CODE);
                JToolBarHelper::title( 'メールグループ作成', 'messaging' );
                JToolBarHelper::save('save','登録');
                JToolBarHelper::cancel('cancel', 'キャンセル');
                if(empty($code)){
                    JToolBarHelper::title( 'メールグループ作成', 'messaging' );
                    $this->setLayout('a00310_add');
                } else {
                    JToolBarHelper::title( 'メールグループ情報編集', 'messaging' );
                    $this->setLayout('a00310_edit');
                }
                
                
            break;
            case 'edit':
                $list = JRequest::getVar('cid');
                $this->update_group = $model->getGroupByCode($list[0]);   
                if($this->update_group->MAGR_USERTYPE != 2)
                    $this->total_group = $model->searchUser(array('type' => $this->update_group->MAGR_USERTYPE));    
                $this->details = $model->getDetails($this->update_group->MAGR_CODE);
                JToolBarHelper::title( 'メールグループ情報編集', 'messaging' );
                JToolBarHelper::save('save','登録');
            	JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('a00310_edit');
                break;
                
            case 'add':                
                JToolBarHelper::title( 'メールグループ作成', 'messaging' );
                JToolBarHelper::save('save','登録');
            	JToolBarHelper::cancel('cancel', 'キャンセル');
                $this->setLayout('a00310_add');
            	break;
            default :
                
                $this->result = &$this->get('Group');
                $this->pagination = &$this->get('Pagination');
            	JToolBarHelper::title( 'メールグループ管理', 'messaging' );
                if($aut->checkAdd())
                    JToolBarHelper::addNew('add','作成');
                if($aut->checkEdit())
            	   JToolBarHelper::editList('edit', '編集');
                if($aut->checkDelete())
            	   JToolBarHelper::deleteList('', 'remove','削除');
                $this->setLayout('a00300');
		}
        
		parent::display();
	}
}




